
import KeyEvent from '../libs/KeyEvent'

var WanbaClientRuntime = function () {
  this.app = undefined
}

WanbaClientRuntime.prototype.init = function (app) {
  this.app = app
  window.wanbaClient = this
  return this
}

WanbaClientRuntime.prototype.ready = function (done) {
  done.call(this)
}

WanbaClientRuntime.prototype.destory = function () {
  this.app = undefined
}

WanbaClientRuntime.prototype.clientInterface = function () {
  return window.wanbaClientInterface
}

WanbaClientRuntime.prototype.clientEnv = function () {
  return window.wanbaClientInterface !== undefined
}

WanbaClientRuntime.prototype.dispatchKeyEvent = function (keyCode, keyAction) {
  if (this.app) {
    this.app.dispatchKeyEvent(KeyEvent.obtain(keyAction, keyCode))
  }
}

WanbaClientRuntime.install = function (Vue, options) {
  Vue.prototype.$wanbaClient = new WanbaClientRuntime()
}

export default WanbaClientRuntime
